package gen.tools.svn;

import gen.tools.Widgets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class IsPathExist extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public IsPathExist() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		final Widgets wid = new Widgets();
		request.setCharacterEncoding( wid.UIcodeSet );
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/text");
		
		final String subsysId = request.getParameter("subsysId");
		final String modUnit = request.getParameter("modUnitId");
		boolean isExist = false;
		
		try {
			ArrayList<String> connSVNInfo = wid.getBaseSVNconnInfo(subsysId,false);	//先檢查OL
			isExist = wid.isPathExist( modUnit,connSVNInfo.get(0),connSVNInfo.get(1),connSVNInfo.get(2) );
			
			if (!isExist) {
				connSVNInfo = wid.getBaseSVNconnInfo(subsysId,true);	//再檢查MR
				isExist = wid.isPathExist(modUnit,connSVNInfo.get(0),connSVNInfo.get(1),connSVNInfo.get(2) );
			}
			
		} catch (Exception e) {
			wid.errLog(e);
		}
		
		response.getWriter().write( String.valueOf(isExist) );
	}

}
